package com.hk.blog.service;

import com.hk.blog.domain.Menu;
import com.hk.commons.query.Order;
import com.hk.commons.util.CollectionUtils;
import com.hk.core.data.jpa.query.specification.Specifications;
import com.hk.core.service.jpa.JpaBaseService;

import java.util.Collections;
import java.util.List;
import java.util.Set;


/**
 * @author Kevin
 */
public interface MenuService extends JpaBaseService<Menu, Long> {

    /**
     * 查询子级菜单
     *
     * @param parentId parentId
     * @return 子级菜单
     */
    default List<Menu> findByParentId(Long parentId) {
        return findAll(Specifications.equals("parentId", parentId), Order.asc("sortBy"));
    }

    default List<Menu> findByParentIds(Set<Long> parentIds) {
        if (CollectionUtils.isEmpty(parentIds)) {
            return Collections.emptyList();
        }
        return findAll(Specifications.in("parentId", parentIds.toArray()), Order.asc("sortBy"));
    }
}
